package ai.taromed.vr.adapters

import ai.taromed.vr.LocalVideoBean
import ai.taromed.vr.R
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnFocusChangeListener
import android.view.ViewGroup
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class VideoInfoAdapter(layoutResId: Int, data: MutableList<LocalVideoBean>?) : BaseQuickAdapter<LocalVideoBean, BaseViewHolder>(layoutResId, data) {

    override fun convert(holder: BaseViewHolder, item: LocalVideoBean) {
        var tv_text = holder.getView<TextView>(R.id.tv_text)
        item?.let{
            tv_text.text = it.title
        }
    }

    override fun createBaseViewHolder(parent: ViewGroup, layoutResId: Int): BaseViewHolder {
        var view = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false)
        view.onFocusChangeListener = OnFocusChangeListener { v, hasFocus ->
            if(hasFocus){
                v.background = parent.context.resources.getDrawable(R.drawable.bg_video_focused_item , null)
            }else{
                v.background = parent.context.resources.getDrawable(R.drawable.bg_video_item , null)
            }
        }
        return BaseViewHolder(view)
    }
}